



// This code is a generated code by a tool
// designed and coded by Shohdi Mohamed Elsheemy ( shohdi@gmail.com )            

using System;
using System.Collections.Generic;
using System.Web;
using System.Data.Common;
using Shohdi.DataHandler;
using System.Data;




namespace DatabaseComponent
{
    
    public partial class HistoryVisitsDB
    {
         string _Connection = "";


        public string Connection
        {
            get { return _Connection; }
            set { _Connection = value; }
        }


       
         string _Provider = "System.Data.SqlClient";

        
        public string Provider
        {
            get { return _Provider; }
            set { _Provider = value; }
        }



        public HistoryVisitsDB()
        {
        }

        public HistoryVisitsDB(string __Connection,params string [] __Provider)
        {

            if (__Provider.Length > 0)
                _Provider = __Provider[0];

            _Connection = __Connection;
            
        }




        public List<HistoryVisits> Select(ClassDataHandler con, string strTop, string strWhere, params DbParameter[] whereParams)
        {
            if (whereParams == null)
                whereParams = new DbParameter[0];

            List<HistoryVisits> lstRet = new List<HistoryVisits>();

            string strQuery = " select " + strTop  + " * from dbo.[HistoryVisits]  " ;

            if (strWhere != "")
            {
                strQuery = strQuery + "  " + strWhere;
            }

            DbDataReader dr = con.SelectDataReader(strQuery, CommandType.Text, whereParams);


            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    HistoryVisits obj = new HistoryVisits();
 if (dr["ID"] != DBNull.Value)
                    {
                        obj.ID = (System.Int64)dr["ID"];
                    }
                    else
                    {
                        obj.ID = -1;
                    } 
 if (dr["NoOfMembers"] != DBNull.Value)
                    {
                        obj.NoOfMembers = (System.Int64)dr["NoOfMembers"];
                    }
                    else
                    {
                        obj.NoOfMembers = -1;
                    } 



                    lstRet.Add(obj);
                   

                }
            }

            dr.Close();


            return lstRet;
        }


        public List<HistoryVisits> Select(string strTop, string strWhere, params DbParameter[] whereParams)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<HistoryVisits> lstRet = Select(con, strTop, strWhere, whereParams);

            con.CloseConnection();

            return lstRet;
        }

        



        public void Insert(ClassDataHandler con , HistoryVisits obj)
        {
            
            

                    DbParameter prmNoOfMembers = con.createParameter();
                    prmNoOfMembers.ParameterName = "@NoOfMembers";
                    prmNoOfMembers.DbType =DbType.Int64;
                    if (obj.NoOfMembers == null)
                    {
                        prmNoOfMembers.Value = DBNull.Value;
                    }
                    else
                    {
                        prmNoOfMembers.Value = obj.NoOfMembers;
                    }
                

                    


           



            string strQuery = " insert into dbo.[HistoryVisits] ([NoOfMembers]) VALUES (@NoOfMembers) ; select SCOPE_IDENTITY() ";
 object scope = con.ExecuteScalar(strQuery, CommandType.Text, prmNoOfMembers);


                    try
                    {
                        obj.ID = System.Int64.Parse(scope.ToString());
                    }
                    catch
                    {
                        obj.ID = -1;
                    }


                    


           

        }



        public void Insert(HistoryVisits obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Insert(con,obj);


            con.CloseConnection();
        }




        public void Update(ClassDataHandler con, HistoryVisits obj)
        {
            
            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


                    DbParameter prmNoOfMembers = con.createParameter();
                    prmNoOfMembers.ParameterName = "@NoOfMembers";
                    prmNoOfMembers.DbType =DbType.Int64;
                    if (obj.NoOfMembers == null)
                    {
                        prmNoOfMembers.Value = DBNull.Value;
                    }
                    else
                    {
                        prmNoOfMembers.Value = obj.NoOfMembers;
                    }
                

                    


           



            string strQuery = " update dbo.[HistoryVisits] set [NoOfMembers]=@NoOfMembers where  [ID]=@ID  ";

            con.ExecuteNonQuery(strQuery, CommandType.Text,prmID,prmNoOfMembers);

            

        }


        public void Update(HistoryVisits obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
            con.OpenConnection();

            Update(con, obj);


            con.CloseConnection();
        }



        public void Delete(ClassDataHandler con, HistoryVisits obj)
        {

            

                    DbParameter prmID = con.createParameter();
                    prmID.ParameterName = "@ID";
                    prmID.DbType =DbType.Int64;
                    if (obj.ID == null)
                    {
                        prmID.Value = DBNull.Value;
                    }
                    else
                    {
                        prmID.Value = obj.ID;
                    }
                

                    


           



           



            string strQuery = " delete from dbo.[HistoryVisits]  where  [ID]=@ID  "; 
                        con.ExecuteNonQuery(strQuery, CommandType.Text,prmID );  

             



        }


        public void Delete( HistoryVisits obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            Delete(con, obj);

            con.CloseConnection();
        }





                    public List<HistoryVisits> getHistoryVisitsByID(ClassDataHandler con,System.Int64 ID)
                    {
                        List<HistoryVisits> lstRet = new List<HistoryVisits>();


                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType = DbType.Int64;
                        if (ID == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmID.Value = ID;
                        }


                        lstRet = Select(con, "" , " where [ID]=@ID ", prmID);



                        return lstRet;

                    }


                    public List<HistoryVisits> getHistoryVisitsByID(System.Int64 ID)
                    {
                        List<HistoryVisits> lstRet = new List<HistoryVisits>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getHistoryVisitsByID(con, ID);

                        con.CloseConnection();

                        return lstRet;

                    }



                

                    public List<HistoryVisits> getHistoryVisitsByNoOfMembers(ClassDataHandler con,System.Int64 NoOfMembers)
                    {
                        List<HistoryVisits> lstRet = new List<HistoryVisits>();


                        DbParameter prmNoOfMembers = con.createParameter();
                        prmNoOfMembers.ParameterName = "@NoOfMembers";
                        prmNoOfMembers.DbType = DbType.Int64;
                        if (NoOfMembers == null)
                        {
                            return lstRet;
                        }
                        else
                        {
                            prmNoOfMembers.Value = NoOfMembers;
                        }


                        lstRet = Select(con, "" , " where [NoOfMembers]=@NoOfMembers ", prmNoOfMembers);



                        return lstRet;

                    }


                    public List<HistoryVisits> getHistoryVisitsByNoOfMembers(System.Int64 NoOfMembers)
                    {
                        List<HistoryVisits> lstRet = new List<HistoryVisits>();

                        ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);
                        con.OpenConnection();

                        lstRet = getHistoryVisitsByNoOfMembers(con, NoOfMembers);

                        con.CloseConnection();

                        return lstRet;

                    }



                

            
public List<HistoryVisits> Search(ClassDataHandler con, HistoryVisits obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID AND ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.NoOfMembers != -1)
                    {
                        DbParameter prmNoOfMembers = con.createParameter();
                        prmNoOfMembers.ParameterName = "@NoOfMembers";
                        prmNoOfMembers.DbType =DbType.Int64;
                        if (obj.NoOfMembers == null)
                        {
                            prmNoOfMembers.Value = DBNull.Value;
                        }
                        else
                        {
                            prmNoOfMembers.Value = obj.NoOfMembers;
                        }
                        strWhere += " [NoOfMembers]=@NoOfMembers AND ";
                        lstParameters.Add(prmNoOfMembers);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("AND"));

                    

            

            List<HistoryVisits> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<HistoryVisits> Search(HistoryVisits obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<HistoryVisits> lstRet = Search(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                

            
public List<HistoryVisits> SearchOrLike(ClassDataHandler con, HistoryVisits obj)
        {
            string strWhere = "";
            List<DbParameter> lstParameters = new List<DbParameter>();

            
                    if (obj.ID != -1)
                    {
                        DbParameter prmID = con.createParameter();
                        prmID.ParameterName = "@ID";
                        prmID.DbType =DbType.Int64;
                        if (obj.ID == null)
                        {
                            prmID.Value = DBNull.Value;
                        }
                        else
                        {
                            prmID.Value = obj.ID;
                        }
                        strWhere += " [ID]=@ID OR ";
                        lstParameters.Add(prmID);
                     }



                    

                    if (obj.NoOfMembers != -1)
                    {
                        DbParameter prmNoOfMembers = con.createParameter();
                        prmNoOfMembers.ParameterName = "@NoOfMembers";
                        prmNoOfMembers.DbType =DbType.Int64;
                        if (obj.NoOfMembers == null)
                        {
                            prmNoOfMembers.Value = DBNull.Value;
                        }
                        else
                        {
                            prmNoOfMembers.Value = obj.NoOfMembers;
                        }
                        strWhere += " [NoOfMembers]=@NoOfMembers OR ";
                        lstParameters.Add(prmNoOfMembers);
                     }



                    


            if (strWhere != "")
                        strWhere = " where " + strWhere.Substring(0, strWhere.LastIndexOf("OR"));

                    

            

            List<HistoryVisits> lstRet = Select(con, "", strWhere, lstParameters.ToArray());

            return lstRet;
        }


        public List<HistoryVisits> SearchOrLike(HistoryVisits obj)
        {
            ClassDataHandler con = new ClassDataHandler(_Connection, _Provider);

            con.OpenConnection();

            List<HistoryVisits> lstRet = SearchOrLike(con,obj);

            con.CloseConnection();

            return lstRet;
        }


                
        


       
        



    }
}











            